<template>
    <div>
        <center>
            <h2>编辑车辆信息</h2>
            <div style="width: 40%;">
                <el-form :model="form" label-width="120px">
                    <el-form-item label="厂商">
                        <el-input v-model="form.carManufacturer"></el-input>
                    </el-form-item>
                    <el-form-item label="指导价(w)">
                        <el-input v-model="form.carGuidePrice"></el-input>
                    </el-form-item>
                    <el-form-item label="库存数量">
                        <el-input v-model="form.carNumber"></el-input>
                    </el-form-item>
                    <el-form-item label="能源类型">
                        <el-input v-model="form.carEnergyType"></el-input>
                    </el-form-item>
                    <el-form-item label="上市时间">
                        <el-date-picker type="month" placeholder="选择日期" v-model="form.carTimeToMarket"
                        ></el-date-picker>
                    </el-form-item>
                    <el-form-item label="最大功率(kw)">
                        <el-input v-model="form.carMaximumPower"></el-input>
                    </el-form-item>
                    <el-form-item label="车身结构">
                        <el-input v-model="form.carBodyStructure"></el-input>
                    </el-form-item>
                    <el-form-item label="外观颜色">
                        <el-input v-model="form.carAppearanceColor"></el-input>
                    </el-form-item>
                    <el-form-item label="换挡形式">
                        <el-input v-model="form.carShiftingMode"></el-input>
                    </el-form-item>
                    <el-form-item label="驱动方式">
                        <el-input v-model="form.carDriveMode"></el-input>
                    </el-form-item>
                    <el-form-item label="变速箱类型">
                        <el-input v-model="form.carTransmissionType"></el-input>
                    </el-form-item>
                    <el-button @click="cancel">取 消</el-button>
                    <el-button type="primary" @click="editCarInfo()">确 定</el-button>
                </el-form>
            </div>
        </center>
    </div>
</template>

<script>
    import {EDIT_CAR_INTO} from "@/api/car/"

    export default {
        name: "Edit-Car",
        data() {
            return {
                dialogFormVisible: false,
                formLabelWidth: '120px',
                form: {
                    carId: '',
                    carManufacturer: '',
                    carGuidePrice: '',
                    carNumber: '',
                    carEnergyType: '',
                    carTimeToMarket: '',
                    carMaximumPower: '',
                    carBodyStructure: '',
                    carAppearanceColor: '',
                    carShiftingMode: '',
                    carDriveMode: '',
                    carTransmissionType: '',
                    version: null,
        },
        }
        },
        methods: {
            cancel() {
                this.$router.push('/car')
            },
            editCarInfo() {
                let data = this.form
                EDIT_CAR_INTO(data).then(res => {
                    if (res.data.code === 5003) {
                        const loading = this.$loading({
                            lock: true,
                            text: 'Loading',
                            spinner: 'el-icon-loading',
                            background: 'rgba(0, 0, 0, 0.7)'
                        });
                        setTimeout(() => {
                            loading.close();
                            this.$router.push('/car')
                        }, 2000);
                        this.$message({
                            showClose: true,
                            message: res.data.message,
                            type: 'success'
                        });
                    } else {
                        this.$message({
                            showClose: true,
                            message: res.data.data,
                            type: 'warning'
                        });
                    }
                })
            }
        },
        created() {
            this.form.carId = this.$route.query.carId
            this.form.carManufacturer = this.$route.query.carManufacturer
            this.form.carGuidePrice = this.$route.query.carGuidePrice
            this.form.carNumber = this.$route.query.carNumber
            this.form.carEnergyType = this.$route.query.carEnergyType
            this.form.carTimeToMarket = this.$route.query.carTimeToMarket
            this.form.carMaximumPower = this.$route.query.carMaximumPower
            this.form.carBodyStructure = this.$route.query.carBodyStructure
            this.form.carAppearanceColor = this.$route.query.carAppearanceColor
            this.form.carShiftingMode = this.$route.query.carShiftingMode
            this.form.carDriveMode = this.$route.query.carDriveMode
            this.form.carTransmissionType = this.$route.query.carTransmissionType
            this.form.version = this.$route.query.version
        },
    }
</script>

<style scoped>
    .el-input {
        width: 100%;
    }
</style>